package com.example.dao;

import com.example.domain.t_comment;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface commentMapper {
    //获取某个文章的评论
    @Select("select * from t_comment where article_id=#{article_id}")
    public List<t_comment> selectAllById(int article_id);
    @Select("select * from t_comment where id=#{id}")
    public t_comment selectById(int id);

    //按照点赞数量排序
    @Select("select * from t_comment where article_id=#{id} order by hits desc")
    public List<t_comment> selectSortHitsById(int id);

    //按照某用户的文章最新评论排序
    @Select("select * from t_comment where article_id=#{id} order by id desc")
    public List<t_comment> selectSortNewsById(int id);
    //全部文章评论排序
    @Select("select * from t_comment  order by id desc")
    public List<t_comment> selectSortNews();
    @Select("select c.* from t_comment c,t_article a  " +
            "where c.article_id=a.id and a.user_id=#{user_id} order by c.id desc")
    public List<t_comment> selectSortUserNews(int user_id);
    //删除（用户）所有评论
    @Delete("delete from t_comment where article_id=#{id}")
    public boolean deleteAllCommentById(int id);
    //某个评论
    @Delete("delete from t_comment where id=#{id}")
    public boolean deleteCommentById(int id);
    //发表评论
    @Insert("insert into t_comment(id,article_id,created,ip," +
            "content,status,author,hits) values(null,#{article_id},#{created}," +
            "#{ip},#{content},#{status},#{author},#{hits})")
    public boolean insertComment(t_comment com);
    //统计所有
    @Select("select count(*) from t_comment ")
    public int countComment();
    //统计user所有
    @Select("select count(*) from t_comment c,t_article a " +
            " where c.article_id=a.id and a.user_id=#{user_id} order by c.id desc")
    public int countCommentser(int user_id);


    @Update("update t_comment set auther=#{newusername} where auther=username")
    void UpdateAuther(String username, String newusername);
}
